package com.test.kotlin04

import android.os.Build
import androidx.annotation.RequiresApi

fun mutableListTest(){
    val mutableList:MutableList<String> = mutableListOf("Jason","jack","jacky")
    mutableList.add("Jimmy")
    mutableList.remove("jack")

    println(mutableList)

    listOf("Jason","jack","jacky").toMutableList();
    val list = mutableListOf("Jason","jack","jacky").toList()
//    list.add("Jimmy")  //不可变列表
//    list.remove("jack")
    println(list)
}


@RequiresApi(Build.VERSION_CODES.N)
fun mutatorTest(){
    val mutableList:MutableList<String> = mutableListOf("Jason","jack","jacky")
    mutableList +="jack222" //类似C++运算符重载
    println(mutableList)

    mutableList.removeIf{
        it.contains("jack")//删除字符串中包含jack字符串的
    }
    println(mutableList)
}


fun main(){
//    mutableListTest()
    mutatorTest()
}